package com.lichuandi.crawler;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/crawler")
public class CrawlerController {
    @GetMapping("/page")
    public  String getPageContent() {
        try {
            String url = "https://www.baidu.com/"; // 要爬取的网页URL
            Document document = Jsoup.connect(url).get();
            String pageContent = document.html();
            return pageContent;
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }
}
